package com.example.backend.controller.admin;

import com.example.backend.common.api.R;
import com.example.backend.dto.OnlineUser;
import com.example.backend.service.OnlineUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 在线用户管理
 */
@RestController
@RequestMapping("/admin/online")
@RequiredArgsConstructor
public class OnlineUserController {
    
    private final OnlineUserService onlineUserService;
    
    /**
     * 获取在线用户列表
     */
    @GetMapping("/list")
    @PreAuthorize("hasAuthority('system:monitor:online:list')")
    public R<List<OnlineUser>> list() {
        return R.ok(onlineUserService.getOnlineUsers());
    }
    
    /**
     * 强制下线
     */
    @DeleteMapping("/{token}")
    @PreAuthorize("hasAuthority('system:monitor:online:logout')")
    public R<Void> forceLogout(@PathVariable String token) {
        onlineUserService.forceLogout(token);
        return R.ok();
    }
} 